package service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import controllers.ValidationUtil;

import models.Administrator;
import models.BaseEntity.PeopleType;
import models.BaseEntity.Status;
import models.Commodity.ChangeQuantityWay;
import models.Commodity.OnSaleStatus;
import models.Commodity;
import models.PricedCommodity;
import models.ShoppingCar;
import models.User;
import models.UserGroup;
import models.UserGroup.UserGroupType;
import play.data.validation.Valid;
import play.db.jpa.JPA;

public class UserService {
	/**
	 * 设置用户所属组。
	 * @param user
	 */
	public static void setGroup(User user) {
		if(user == null) return;
		List<UserGroup> groups = user.groups;
		if(ValidationUtil.isEmpty(groups)) {
			UserGroup defaultGroup = UserGroup.find("byIsDefault", true).first();
			user.group = defaultGroup;
		} else {
			for(UserGroup g : groups) {
				if(g.type == UserGroupType.INHERENCE) {
					user.group = g;
					break;
				}
			}
		}
	}
	
	/**
	 * 设置用户所属组。
	 * @param users
	 */
	public static void setGroup(List<User> users) {
		if(users != null) {
			for(User user : users) {
				setGroup(user);
			}
		}
	}
}
